package com.team12.hotel404.controller.admin;

import com.team12.hotel404.domain.City;
import com.team12.hotel404.domain.CityExample;
import com.team12.hotel404.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping(value = "/city")
public class CityController {
    @Autowired
    private CityService cityService;

    @RequestMapping(value = "/list")
    public String list_all_cities(Model model){
        List<City> cities = cityService.listAllCiyt();
        model.addAttribute("cities",cities);
        return "admin/city-list";
    }

    @RequestMapping(value = "findByid")
    public String find_by_id(Integer id,Model model){
        City city = cityService.findById(id);
        model.addAttribute("city",city);
        return "admin/city-update";
    }

    @RequestMapping(value = "update")
    public String update(City city){
        cityService.updateCityInfo(city);
        return "redirect:/city/list";
    }

}
